package com.example.ycymyapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

public class Xinxi_BaochunActivity extends AppCompatActivity {
    TextView tv_msg;
    SharedPreferences preferences;
    SharedPreferences.Editor editor;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_xinxi__baochun);
        tv_msg=findViewById(R.id.tv_msg);
    }

    public void dealuser(View view) {
        switch (view.getId()){
            case R.id.btn_set:
                preferences =getSharedPreferences("user",MODE_PRIVATE);
                editor = preferences.edit();
                editor.putString("id","1001");
                editor.putString("pwd","1234");
                editor.apply();
                editor.commit();
                Toast.makeText(this, "保存数据成功", Toast.LENGTH_SHORT).show();
                /*preferences = getSharedPreferences("my",MODE_PRIVATE);
                editor = preferences.edit();
                editor.putString("id","1001");
                editor.apply();*/
            break;
            case R.id.btn_get:
                preferences =getSharedPreferences("user",MODE_PRIVATE);
                String id = preferences.getString("id","id");
                String pwd = preferences.getString("pwd","pwd");
                tv_msg.setText("id:"+id+"\n"+"pwd:"+pwd);
                break;
            case R.id.btn_clear:
                preferences =getSharedPreferences("my",MODE_PRIVATE);
                editor = preferences.edit();
                editor.clear();
                editor.apply();
                tv_msg.setText("");
                Toast.makeText(this, "清除数据成功", Toast.LENGTH_SHORT).show();
                break;
        }
    }
}
